package com.tlgen.adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;

import androidx.recyclerview.widget.RecyclerView;

import com.tlgen.R;
import com.tlgen.bean.PayOrder;
import com.xuexiang.xui.widget.textview.supertextview.SuperTextView;

import java.util.ArrayList;

public class PayOrderAdapter extends RecyclerView.Adapter<PayOrderAdapter.myViewHodler> {
    private Context context;
    private ArrayList<PayOrder> payOrderArrayList;

    //构造方法，传入数据
    public PayOrderAdapter(Context context, ArrayList<PayOrder> payOrderArrayList){
        this.context = context;
        this.payOrderArrayList = payOrderArrayList;
    }

    @Override
    public PayOrderAdapter.myViewHodler onCreateViewHolder(ViewGroup parent, int viewType) {
        View itemView = View.inflate(context, R.layout.activity_repay_item, null);
        return new PayOrderAdapter.myViewHodler(itemView);
    }

    @Override
    public void onBindViewHolder(PayOrderAdapter.myViewHodler holder, int position) {
        PayOrder payOrder = payOrderArrayList.get(position);
        holder.orderNo.setCenterString(payOrder.getOrderNo());
        holder.outTradeNo.setCenterString(payOrder.getOutTradeNo());
        holder.payNo.setCenterString(payOrder.getPayNo());
        holder.money.setCenterString(payOrder.getMoney());
        holder.body.setCenterString(payOrder.getBody());
        holder.mchid.setCenterString(payOrder.getMchid());
        holder.payChannel.setCenterString("alipay".equals(payOrder.getPayChannel()) ? "支付宝" : "微信");
        holder.payType.setCenterString("alipay".equals(payOrder.getPayType()) ? "支付宝" : "微信");
        holder.payStatus.setCenterString(payOrder.getPayStatus() == 1 ? "支付成功" : "支付失败");
        holder.addTime.setCenterString(payOrder.getAddTime());
    }

    @Override
    public int getItemCount() {
        return payOrderArrayList.size();
    }

    class myViewHodler extends RecyclerView.ViewHolder {
        SuperTextView orderNo;
        SuperTextView outTradeNo;
        SuperTextView payNo;
        SuperTextView money;
        SuperTextView body;
        SuperTextView mchid;
        SuperTextView payChannel;
        SuperTextView payType;
        SuperTextView payStatus;
        SuperTextView addTime;
        public myViewHodler(View itemView) {
            super(itemView);
            orderNo = (SuperTextView) itemView.findViewById(R.id.orderNo);
            outTradeNo = (SuperTextView) itemView.findViewById(R.id.outTradeNo);
            payNo = (SuperTextView) itemView.findViewById(R.id.payNo);
            money = (SuperTextView) itemView.findViewById(R.id.money);
            body = (SuperTextView) itemView.findViewById(R.id.body);
            mchid = (SuperTextView) itemView.findViewById(R.id.mchid);
            payChannel = (SuperTextView) itemView.findViewById(R.id.payChannel);
            payType = (SuperTextView) itemView.findViewById(R.id.payType);
            payStatus = (SuperTextView) itemView.findViewById(R.id.payStatus);
            addTime = (SuperTextView) itemView.findViewById(R.id.addTime);
        }
    }
}
